package com.test.example.controller.oss;

import cn.hutool.core.io.FileUtil;
import com.xingluo.oss.core.StandardOssClient;
import com.xingluo.oss.core.ali.AliOssClient;
import com.xingluo.oss.core.ali.authorize.AliOssStsToken;
import com.xingluo.oss.model.OssInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/oss")
public class OssController {

    @Resource(name = "aliOssClient")
    private StandardOssClient aliOssClient;

    @Resource(name = "minioOssClient")
    private StandardOssClient minioOssClient;

    @GetMapping("/aliUpLoad")
    public String upLoad() {
        OssInfo ossInfo = aliOssClient.upLoad(FileUtil.getInputStream("/Users/longyin/Downloads/9ddc9bb7126138f99fe2fea36a50d280.jpeg"), "test.png");
        System.out.println(ossInfo);
        return ossInfo.getUrl();
    }

    @DeleteMapping("/deleteFile")
    public String deleteFile() {
        aliOssClient.delete("test.png");
        return "成功";
    }

    @DeleteMapping("/deleteFile1")
    public String deleteFile1() {
        aliOssClient.delete("https://gongxiaoyihuo.oss-cn-hangzhou.aliyuncs.com/test.png");
        return "成功";
    }

    @GetMapping("/sts")
    public String sts() {
        AliOssStsToken ossSTSToken = ((AliOssClient)aliOssClient).getOssSTSToken();
        System.out.println(ossSTSToken);
        return ossSTSToken.stsToken;
    }

    @GetMapping("/minio")
    public String minio() {
        OssInfo ossInfo = minioOssClient.upLoad(FileUtil.getInputStream("/Users/longyin/Downloads/9ddc9bb7126138f99fe2fea36a50d280.jpeg"), "test.png");
        System.out.println(ossInfo);
        return ossInfo.getUrl();
    }
}
